package com.wondedDream.service.impl;

import com.wondedDream.model.CourseCategory;
import com.wondedDream.repository.CourseCategoryRepository;
import com.wondedDream.service.CourseCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CourseCategoryServiceImpl implements CourseCategoryService {
    @Autowired
    private CourseCategoryRepository courseCategoryRepository;

    @Override
    public CourseCategory saveCourseCategory(CourseCategory category) {
        return courseCategoryRepository.save(category);
    }

    @Override
    public CourseCategory getCourseCategoryById(Integer id) {
        return courseCategoryRepository.findById(id).orElse(null);
    }

    @Override
    public List<CourseCategory> getAllCourseCategories() {
        return courseCategoryRepository.findAll();
    }

    @Override
    public void deleteCourseCategory(Integer id) {
        courseCategoryRepository.deleteById(id);
    }

    @Override
    public CourseCategory updateCourseCategory(CourseCategory category) {
        return courseCategoryRepository.saveAndFlush(category);
    }
}